package com.leozhang.portalssm.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.leozhang.portalssm.entity.Assets;
import com.leozhang.portalssm.entity.AssetsExample;
import com.leozhang.portalssm.entity.AssetsStatus;
import com.leozhang.portalssm.entity.AssetsStatusExample;
import com.leozhang.portalssm.mapper.AssetsStatusMapper;
import com.leozhang.portalssm.service.AssetsStatusService;
import com.leozhang.portalssm.util.ChangeChar;
import com.leozhang.portalssm.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AssetsStatusImpl implements AssetsStatusService {

    @Autowired
    private AssetsStatusMapper assetsStatusMapper;

    @Override
    public Result getListForPage(int pno, int psize, String assetStatusName, String sortField, String sortType) {
        Page<Object> p = PageHelper.startPage(pno, psize);
        AssetsStatusExample assetsStatusExample = new AssetsStatusExample();
        AssetsStatusExample.Criteria criteria = assetsStatusExample.createCriteria();
        if(assetStatusName.trim().length()>0){
            criteria.andAssetStatusNameLike("%"+assetStatusName+"%");
        }
        if(sortField.trim().length()>0){
            assetsStatusExample.setOrderByClause(ChangeChar.camelToUnderline(sortField,2) +""+sortType);
        }
        List<AssetsStatus> list = assetsStatusMapper.selectByExample(assetsStatusExample);
        return Result.end(200,list,"查询成功",p.getTotal());
    }

    @Override
    public void insertAssets(AssetsStatus assetsStatus) {
        assetsStatusMapper.insert(assetsStatus);
    }

    @Override
    public AssetsStatus selectAssetsById(Long id) {
        AssetsStatus assetsStatus = assetsStatusMapper.selectByPrimaryKey(id);
        return assetsStatus;
    }

    @Override
    public void updateAssetsstatus(AssetsStatus assetsStatus) {
          assetsStatusMapper.updateByPrimaryKeySelective(assetsStatus);
    }

    @Override
    public void deleteAssetsStatusById(Long id) {
          assetsStatusMapper.deleteByPrimaryKey(id);
    }
}
